# Maintainer: Peltoche <dev@halium.fr>
# Co-maintainer: Andrea Pascal <andrea@anodium.net>
# Co-Maintainer: Deeraurty at github

_realname=lsd
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.23.1
pkgrel=2
pkgdesc="The next gen ls command (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/Peltoche/lsd"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
#depends=()
#optdepends=('powerline-fonts: powerline symbols for terminals'
#            'nerd-fonts-complete: popular collections such as Font Awesome & fonts such as Hack')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/Peltoche/lsd/archive/refs/tags/${pkgver}.tar.gz"
        "old-windows-aarch64.patch")
sha256sums=('9698919689178cc095f39dcb6a8a41ce32d5a1283e6fe62755e9a861232c307d'
            'd5af6a44b5309465faa8485e74062dfc30705acd08d8f5a9bc02431f6894edd2')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  cargo vendor \
    --locked \
    --versioned-dirs

  mkdir -p .cargo
  cat >> .cargo/config.toml <<END
[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "vendor"
END

  patch -Np1 -i "${srcdir}/old-windows-aarch64.patch"
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  export SHELL_COMPLETIONS_DIR="$PWD/completions"
  export WINAPI_NO_BUNDLED_LIBRARIES=1
  cargo build --release --frozen
}

check() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # Unset lower-cased envs temp and tmp
  # that points to AppData/Local/Temp
  # to pass 
  #   - test_list_almost_all_empty_directory 
  #   - test_list_all_empty_directory
  unset temp
  unset tmp

  cargo test --release --frozen
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  cargo install \
    --offline \
    --no-track \
    --frozen \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}"

  install -Dm644 LICENSE "$pkgdir${MINGW_PREFIX}/share/licenses/$pkgname/LICENSE"
  install -Dm644 completions/_lsd "$pkgdir${MINGW_PREFIX}/share/zsh/site-functions/_lsd"
  install -Dm644 completions/lsd.bash "$pkgdir${MINGW_PREFIX}/share/bash-completion/completions/lsd"
  install -Dm644 completions/lsd.fish "$pkgdir${MINGW_PREFIX}/share/fish/vendor_completions.d/lsd.fish"
}
